package website.seamonster.ethegg.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import website.seamonster.ethegg.dataobject.Chicken;

import javax.transaction.Transactional;

/**
 * Created by 罗海量
 * 2018-07-17 18:58
 */
public interface ChickenRepository extends JpaRepository<Chicken, Long> {
    @Query("select count(c) from Chicken c where c.userId=?1")
    int getCountByUserId(String userId);

    //CAUTION：只能测试用！
    @Modifying
    @Transactional
    @Query("update Chicken c set c.bornNum=c.bornNum+1 where c.id=?1")
    int bornEgg(Long id);

    //CAUTION：应该只有测试用到
    @Modifying
    @Transactional
    @Query("delete from Chicken c where c.id=?1")
    int deleteById(Long id);
}
